package com.zls.util;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

public class QueryrunnerWrapper {
	private static QueryRunner qr = new QueryRunner(DruidUtil.getDataSource(),true);
	
	
//	public <T> List<T> queryList(String sql,BeanListHandler<T> rsh) {
//		try {
//			return qr.query(sql, rsh);
//		} catch (SQLException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//			throw new RuntimeException("操作数据库失败");
//		}
//	}
	
	public static <T> List<T> query( String sql,BeanListHandler<T> rsh) {
        List<T> entityList = null;
        try {
            entityList = qr.query( sql, rsh);
        } catch (SQLException e) {
            throw new RuntimeException("操作错误:"+e.getMessage());
        }
        return entityList;
    }
	
	public static int update(String sql,Object... params) {
		int n=0;
		try {
			n = qr.update(sql, params);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			 throw new RuntimeException("操作错误:"+e.getMessage());
		}
		return n;
	}
}
